/**    
 * 文件名：Ex3Threshold.java    
 *    
 * 版本信息：    
 * 日期：2014年3月10日    
 * xyj 足下 xyj 2014     
 * 版权所有    
 *    
 */
package opencvtest.chapter04;

import static com.googlecode.javacv.cpp.opencv_core.cvGetSize;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_GRAYSCALE;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_THRESH_BINARY;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvThreshold;
import static opencvtest.OpenCVUtils.loadAndShowOrExit;
import static opencvtest.OpenCVUtils.show;

import java.io.File;

import com.googlecode.javacv.cpp.opencv_core.IplImage;

/**
 * The third example for section "Computing the image histogram" in Chapter 4,
 * page 93. Separates pixels in an image into a foreground (black) and
 * background (white) using OpenCV `cvThreshold` method.
 */
public class Ex3Threshold {

    public static void main(String[] args) {

        IplImage src = loadAndShowOrExit(new File("data/group.jpg"), CV_LOAD_IMAGE_GRAYSCALE);

        IplImage dest = IplImage.create(cvGetSize(src), src.depth(), src.nChannels());

        cvThreshold(src, dest, 60, 255, CV_THRESH_BINARY);

        show(dest, "Thresholded");
    }

}
